using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraBars;
using MiragePWF.Common.Container;
using Wolfut.MirageEE.UI.UIBaseComponents;

using Wolfut.MirageEE.UI.UI.Common;


namespace Wolfut.MirageEE.Client
{
    public partial class MainForm1 : DevExpress.XtraEditors.XtraForm
    {
        public MainForm1()
        {
            InitializeComponent();
        }

        #region "ShowMdiForm"
        private Dictionary<String, String> barButton = null;
        private void ShowMdiForm(string formName)
        {
            this.Cursor = Cursors.WaitCursor;

            MirageEEFormBase form = IOC.Resolve<MirageEEFormBase>(formName) as MirageEEFormBase;
            foreach (MirageEEFormBase frm in this.MdiChildren)
            {
                if (frm.Name == form.Name)
                {
                    frm.Activate();
                    form = frm;
                    break;
                }
            }
            form.MdiParent = this;
            form.WindowState = this.WindowState;
            form.Show();
            this.Cursor = Cursors.Arrow;
        }
        #endregion

        private void MainForm1_Load(object sender, EventArgs e)
        {
            barButton = new Dictionary<string, string>();
            barButton.Add(this.barButtonItemProject.Name, "ProjectForm");
            barButton.Add(this.barButtonItemBillCodeRules.Name, "BillCodeRuleForm");
            barButton.Add(this.barButtonItemCodeRule.Name, "CodeRuleForm");
            barButton.Add(this.barButtonItemCurrencyCategory.Name, "CurrencyCategoryForm");
            barButton.Add(this.barButtonItemSysSetting.Name, "SysParamForm");
            barButton.Add(this.barButtonItemCompany.Name, "FirmForm");
            barButton.Add(this.barButtonItemDepartment.Name, "DepartmentForm");
            barButton.Add(this.barButtonItemEmployee.Name, "EmployeeForm");
            barButton.Add(this.barButtonItemSubject.Name, "SubjectForm");
            barButton.Add(this.barButtonItemDataDic.Name, "DataDictionaryForms");
            barButton.Add(this.barButtonWareHouse.Name, "WarehouseForm");

            barButtonItemProject.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonItemBillCodeRules.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonItemCodeRule.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonItemCurrencyCategory.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonItemSysSetting.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonItemCompany.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonItemDepartment.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonItemEmployee.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonItemSubject.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonItemDataDic.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);
            barButtonWareHouse.ItemClick += new ItemClickEventHandler(this.barButtonItem_ItemClick);            
        }    

        private void barButtonItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {          
            if (!barButton.ContainsKey(e.Item.Name))
            {
                return;
            }
            ShowMdiForm(barButton[e.Item.Name]);
        }

        private void barButtonItemAddSupplier_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            new LoginForm().Show();
        }                    
    }
}